package org.jeecg.modules.clue.job;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.clue.entity.ClueRecordTask;
import org.jeecg.modules.clue.service.IClueRecordTaskService;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 示例带参定时任务
 *
 * @Author Scott
 */
@Slf4j
@Component
@DisallowConcurrentExecution
public class ClueTaskIzSyncYJob implements Job {

    /**
     * 若参数变量名修改 QuartzJobController中也需对应修改
     */
    private String parameter;

    public void setParameter(String parameter) {
        this.parameter = parameter;
    }

    @Resource
    IClueRecordTaskService clueRecordTaskService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        log.info("ClueTaskIzSyncYJob 定时任务");

        List<ClueRecordTask> taskList = clueRecordTaskService.list(new LambdaQueryWrapper<ClueRecordTask>().isNotNull(ClueRecordTask::getChannelInviteStatus));
        for (ClueRecordTask clueRecordTask : taskList) {
            clueRecordTask.setIzSync("1");
        }
        clueRecordTaskService.updateBatchById(taskList);


    }


}
